package henu.innovation.service.impl;

import henu.innovation.entity.Admin;
import henu.innovation.mapper.AdminMapper;
import henu.innovation.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    public AdminMapper adminMapper;

    @Override
    public List<Admin> findAllAdmins() {
        return adminMapper.findAllAdmins();
    }

    @Override
    public Admin login(String username,String password) {
        Admin admin = new Admin();
        if(adminMapper.findAllAdmins().isEmpty()
                && username.equals("admin")
                && password.equals("admin")){
            return admin;
        }
        try{
            admin = adminMapper.login(username,password);
        }
        catch (Exception e){
            System.out.println(e);
        }
        return admin;
    }

    @Override
    public Admin findAdminById(int id) {
        return adminMapper.findAdminById(id);
    }

    @Override
    public boolean updateAdmin(Admin admin) {
        return adminMapper.updateAdmin(admin);
    }

    @Override
    public boolean addAdmin(Admin admin) {
        return adminMapper.addAdmin(admin);
    }

    @Override
    public boolean deleteAdminById(int id) {
        return adminMapper.delete(id);
    }

    @Override
    public Admin findAdminByName(String username) {
        return adminMapper.findAdminByName(username);
    }
}
